package com.cssnj.portal.service.query;

import io.predictech.framework.domain.common.JsonRequest;
import io.predictech.framework.domain.common.JsonResponse;
import io.predictech.framework.domain.exception.BaseException;
import io.predictech.framework.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service("query03Service")
public class Query03Service extends BaseService {

    @Qualifier("fourthJdbcTemplate")
    @Autowired
    private JdbcTemplate fourthJdbcTemplate;

    @Override
    protected JsonResponse invokingService(JsonRequest jsonRequest) throws SQLException, BaseException {
        switch (jsonRequest.getHandleCode()) {
            case "queryData":
                return queryData(jsonRequest);
        }
        return null;
    }

    protected JsonResponse queryData(JsonRequest jsonRequest) {
        JsonResponse jsonResponse = new JsonResponse();
        String swjgdm = (String)jsonRequest.getReqData().get("swjgdm");
        List<Object> params = new ArrayList<Object>();
        params.add(swjgdm);
        List<Map<String, Object>> dataList = queryDao.queryForList(fourthJdbcTemplate,
                     "SELECT SWJG_MC,    \n" +
                        "       LSKQY_HS,   \n" +
                        "       SWYXQY_HS,  \n" +
                        "       YBWYXQY_HS, \n" +
                        "       WBWYXQY_HS, \n" +
                        "       YQWYXQY_HS, \n" +
                        "       WQWYXQY_HS, \n" +
                        "       WQWYSQY_HS, \n" +
                        "       LSKQY_JE,   \n" +
                        "       SWYXQY_JE,  \n" +
                        "       YBWYXQY_JE, \n" +
                        "       WBWYXQY_JE, \n" +
                        "       YQWYXQY_JE, \n" +
                        "       WQWYXQY_JE, \n" +
                        "       WQWYSQY_JE  \n" +
                        "  FROM CX_QYNSRSRJJQK WHERE SWJG_DM = ? ",params);
        if(dataList.size()>0) {
              jsonResponse.getRepData().put("data", dataList.get(0));
         }
        return jsonResponse;
    }

}
